/** 
 * Project Name:ZhiWeiCateringManagementSystem 
 * File Name:DishOrderRecordAction.java 
 * Package Name:cn.ccit.servers 
 * Date:2016年11月5日下午7:18:38 
 * Copyright (c) 2016, 120026139@qq.com All Rights Reserved. 
 * 
*/  
  
package cn.ccit.action;  

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ModelDriven;

import cn.ccit.entites.record.DishOrderRecord;
import cn.ccit.entites.record.DishOrderRecordItem;
import cn.ccit.iservers.IDishOrderRecordItemServers;
import cn.ccit.iservers.IDishOrderRecordServers;
import cn.ccit.model.BaseModel;
import cn.ccit.servers.DishOrderRecordItemServers;
import cn.ccit.servers.DishOrderRecordServers;

/** 
 * ClassName:DishOrderRecordAction <br/> 
 * Function: 点菜记录表 <br/> 
 * Reason:    <br/> 
 * Date:     2016年11月5日 下午7:18:38 <br/> 
 * @author   Administrator 
 * @version   
 * @since    JDK 1.6 
 * @see       
 */
public class DishOrderRecordAction extends BaseRecordAction implements ModelDriven<DishOrderRecord>{
	
	/** 
	 * serialVersionUID:(版本号). 
	 * @since JDK 1.6 
	 */   
	private static final long serialVersionUID = 1L;
	private IDishOrderRecordServers iOrderRecordServers =new DishOrderRecordServers();
	private DishOrderRecord dishOrder =new DishOrderRecord();
	private IDishOrderRecordItemServers  iOrderRecordItemServers = new DishOrderRecordItemServers();
	private String itemList;
	
	@Override
	public String addData() {
		sendJsonData(iOrderRecordServers.addDishOrderRecord(dishOrder), new BaseModel<DishOrderRecord>());
		return super.addData();
	}

	@Override
	public String removeData() {
		sendJsonData(iOrderRecordServers.removeDishOrderRecord(dishOrder), new BaseModel<DishOrderRecord>());
		return super.removeData();
	}

	@Override
	public String changeDataInfo() {
		sendJsonData(iOrderRecordServers.changeDishOrderRecordInfo(dishOrder), new BaseModel<DishOrderRecord>());
		return super.changeDataInfo();
	}

	@Override
	public String getDataList() {
		sendJsonDataList(iOrderRecordServers.getSomeDishOrderRecords(startId, limit), 
				new BaseModel<List<DishOrderRecord>>());
		return super.getDataList();
	}

	@Override
	public String sreachDataById() {
		DishOrderRecord dor=iOrderRecordServers.searchDishOrderRecordByID(dishOrder.getId());
		sendJsonData(dor!=null,
				new BaseModel<DishOrderRecord>(),
				dor);
		return super.sreachDataById();
	}	

	@Override
	public DishOrderRecord getModel() {
		return dishOrder;
	}

	@Override
	public String searchDataListByYear() {
		sendJsonDataList(iOrderRecordServers.searchDishOrderRecordByYear(dishOrder.getOrderYear()),
				new BaseModel<List<DishOrderRecord>>());
		return super.searchDataListByYear();
	}

	@Override
	public String searchDataListByMonth() {
		sendJsonDataList(iOrderRecordServers.searchDishOrderRecordByMonth(dishOrder.getOrderMonth()),
				new BaseModel<List<DishOrderRecord>>());
		return super.searchDataListByMonth();
	}

	@Override
	public String searchDataListByDate() {
		List<DishOrderRecord> arr=iOrderRecordServers.searchDishOrderRecordByDate(dishOrder.getOrderDate());
		//System.out.println(arr.get(0).getSerialsNumber());
		sendJsonDataList(arr,
				new BaseModel<List<DishOrderRecord>>());
		return super.searchDataListByDate();
	}
	/**
	 * 
	 * @方法功能说明：用于点菜  
	 * @创建：2016年11月14日 by Administrator   
	 * 修改：日期 by 修改者  
	 * 修改内容：  
	 * @参数： @return      
	 * @return String     
	 * @throws
	 */
	public String orderDish() {
		long ser=iOrderRecordServers.orderDish(dishOrder, itemList);
		sendJsonData(ser!=0,
				new BaseModel<Long>(),
				ser);
		System.out.println(itemList);
		return Action.SUCCESS;
	}

	public String getItemList() {
		return itemList;
	}

	public void setItemList(String itemList) {
		this.itemList = itemList;
	}

	@Override
	public String searchDataListBySerialsNumber() {
		Map<String, Object> mapTemp =new HashMap<String, Object>();
		mapTemp.put("orderRecord", iOrderRecordServers.
				searchDishOrderRecordBySerialsNumber(dishOrder.getSerialsNumber()));
		mapTemp.put("orderRecordItem", 
				iOrderRecordItemServers.searchDishOrderRecordItemBySerialsNumber(
						dishOrder.getSerialsNumber()));
		sendJsonDataMap(mapTemp,
				new BaseModel<Map<String, Object>>());
		return super.searchDataListBySerialsNumber();
	}
	
	/**
	 * 
	 * 方法功能说明：  执行支付操作
	 * 创建：2016年11月15日 by Administrator   
	 * 修改：日期 by 修改者  
	 * 修改内容：  
	 * @参数： @return      
	 * @return String     
	 * @throws
	 */
	public String payForOrder() {
		sendJsonData(iOrderRecordServers.payForOrder(dishOrder.getSerialsNumber()),
				new BaseModel<Long>());
		return Action.SUCCESS;
	}
}
